package com.buptlogistics.creditinvestigation.app; /**
 * 系统项目名称
 * com.hmammon.accounting.app
 * AppData.java
 * <p/>
 * 2014-5-22-下午1:48:28
 * 2014兴财富汇（北京）信息技术有限公司-版权所有
 */

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


/**
 * AppData
 * <p/>
 * fuxuemingzhu 2014-5-22 下午1:48:28
 *
 * @version 1.0.0
 */
public class AppData {

    private static AppData mInstance;

    public static final String COMPANY_PROJECT_NAMESPACE = "com.buptlogistics.creditassess";
    private static final String KEY_SHOW_WELCOME = "isFirstRun";
    private static final String USERNAME = "user_name";
    private static final String USER_PASSWORD = "user_password";
    private static final String USER_COMPANY = "user_company";
    private static final String TOOKEN = "user_token";
    private static final String ISLOGIN = "login";
    private static final String USERINFOR = "user_json";
    private static final String BYRINFOR = "byr_information";
    private static final String USERID = "user_id";
    private static final String PASSWORD = "password";
    private static final String SCHOOL = "school";
    private static final String CORE_BUSINESS = "core_business";
    private static final String COMPANY_CODE = "company_code";
    private static final String COMPANY_INFO = "company_info";
    private static final String COMPANY_CHANCE = "company_chance";
    private static final String APPLY_ENTITY = "apply_entity";
    private static final String COLLATERAL_ENTITY = "collateral_entity";
    private static final String APPLY_TYPE = "apply_type";
    private static final String SALE_COMPANY = "sale_company";
    public static SharedPreferences spf;
    public static Editor editor;

    /**
     * 设置分页内容的字体格式
     */
    public static final int NOTIFY_TEXT = 24;
    public static final int SELLP_TEXT = 18;

    /**
     * 创建一个新的实例 AppData.
     */
    private AppData(Context context) {
        spf = context.getSharedPreferences(COMPANY_PROJECT_NAMESPACE,
                Context.MODE_PRIVATE);
    }

    public static AppData getInstance(Context context) {
        if (mInstance == null) {
            synchronized (AppData.class) {
                if (mInstance == null) {
                    mInstance = new AppData(context);
                    if (spf != null) {
                        editor = spf.edit();
                    }
                }
            }
        }
        return mInstance;
    }

    public static void initData(Context ctx) {
        spf = ctx.getSharedPreferences(COMPANY_PROJECT_NAMESPACE,
                Context.MODE_PRIVATE);
        if (spf != null) {
            editor = spf.edit();
        }
    }

    /**
     * saveData(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param key void
     *
     * @throws
     * @since 1.0.0
     */
    public static void saveData(String key, boolean value) {
        // TODO Auto-generated method stub
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static void saveData(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }

    public static void saveData(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
    }

    public static String getData(String key) {
        return spf.getString(key, "");
    }

    /**
     * getBoolean(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @return boolean
     *
     * @throws
     * @since 1.0.0
     */
    public static boolean getBoolean(String key, boolean defaultValue) {
        // TODO Auto-generated method stub
        return spf.getBoolean(key, defaultValue);
    }

    /**
     * 清除指定数据
     *
     * @param key
     */
    public static void clearData(String key) {
        editor.remove(key);
        editor.commit();
    }

    public boolean isFirstRun() {
        return spf.getBoolean(KEY_SHOW_WELCOME, true);
    }

    public void disableFirstRun() {
        Editor editor = spf.edit();
        editor.putBoolean(KEY_SHOW_WELCOME, false);
        editor.commit();
    }

    /**
     * <p>
     * Title: getClassNum
     * </p>
     * <p>
     * Description:返回当前选择的班级号
     * </p>
     *
     * @return
     */
    public String getUsername() {
        return spf.getString(USERNAME, "@null");
    }

    /**
     * <p>
     * Title: saveClassNum
     * </p>
     * <p>
     * Description:保存当前选择的班级号
     * </p>
     *
     * @param class_num
     */
    public void saveUsername(String class_num) {
        Editor editor = spf.edit();
        editor.putString(USERNAME, class_num);
        editor.commit();
    }

    /**
     * <p>
     * Title: getClassNum
     * </p>
     * <p>
     * Description:返回当前选择的班级号
     * </p>
     *
     * @return
     */
    public String getSchool() {
        return spf.getString(SCHOOL, "benbu");
    }

    /**
     * <p>
     * Title: saveClassNum
     * </p>
     * <p>
     * Description:保存当前选择的班级号
     * </p>
     */
    public void saveSchool(String school) {
        Editor editor = spf.edit();
        editor.putString(SCHOOL, school);
        editor.commit();
    }

    /**
     * <p>
     * Title: saveUserInfo
     * </p>
     * <p>
     * Description:保存用户信息/箭扣
     * </p>
     *
     * @param userInfo
     */
    public void saveUserInfo(String userInfo) {
        Editor editor = spf.edit();
        editor.putString(USERINFOR, userInfo);
        editor.commit();
    }

    /**
     * <p>
     * Title: getUserInfo
     * </p>
     * <p>
     * Description:获取用户信息
     * </p>
     *
     * @return
     */
    public String getUserInfo() {
        return spf.getString(USERINFOR, "");
    }

    /**
     * <p>
     * Title: saveUserInfo
     * </p>
     * <p>
     * Description:保存用户信息/箭扣
     * </p>
     */
    public void setUserId(String userId) {
        Editor editor = spf.edit();
        editor.putString(USERID, userId);
        editor.commit();
    }

    /**
     * <p>
     * Title: getUserInfo
     * </p>
     * <p>
     * Description:获取用户信息
     * </p>
     *
     * @return
     */
    public String getUserId() {
        return spf.getString(USERID, "");
    }


    /**
     * <p>
     * Title: saveUserInfo
     * </p>
     * <p>
     * Description:保存用户信息
     * </p>
     */
    public void saveByrInfo(String byrInfo) {
        Editor editor = spf.edit();
        editor.putString(BYRINFOR, byrInfo);
        editor.commit();
    }

    /**
     * <p>
     * Title: getUserInfo
     * </p>
     * <p>
     * Description:获取用户信息
     * </p>
     *
     * @return
     */
    public String getByrInfo() {
        return spf.getString(BYRINFOR, "");
    }

    /**
     * <p>
     * Title: saveUserInfo
     * </p>
     * <p>
     * Description:保存用户信息
     * </p>
     */
    public void saveTooken(String tooken) {
        Editor editor = spf.edit();
        editor.putString(TOOKEN, tooken);
        editor.commit();
    }

    /**
     * <p>
     * Title: getUserInfo
     * </p>
     * <p>
     * Description:获取用户信息
     * </p>
     *
     * @return
     */
    public String getTooken() {
        return spf.getString(TOOKEN, "");
    }


    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:学期开始日 "yyyy-MM-dd"
     * </p>
     */
    public void setPassword(String password) {
        Editor editor = spf.edit();

        editor.putString(USER_PASSWORD, password);
        editor.commit();
    }


    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setLogin(boolean isLogin) {
        Editor editor = spf.edit();
        AppData.saveData(ISLOGIN, isLogin);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public boolean getIsLogin() {
        return spf.getBoolean(ISLOGIN, false);
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setCoreBusiness(String coreBusiness) {
        Editor editor = spf.edit();
        AppData.saveData(CORE_BUSINESS, coreBusiness);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getCoreBuiness() {
        return spf.getString(CORE_BUSINESS, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setCompanyCode(String companyCode) {
        Editor editor = spf.edit();
        AppData.saveData(COMPANY_CODE, companyCode);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getCompanyCode() {
        return spf.getString(COMPANY_CODE, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setCompanyInfo(String companyInfo) {
        Editor editor = spf.edit();
        AppData.saveData(COMPANY_INFO, companyInfo);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getCompanyInfo() {
        return spf.getString(COMPANY_INFO, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setSaleCompany(String saleCompany) {
        Editor editor = spf.edit();
        AppData.saveData(SALE_COMPANY, saleCompany);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getSaleCompany() {
        return spf.getString(SALE_COMPANY, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setCompanyChance(String companyChance) {
        Editor editor = spf.edit();
        AppData.saveData(COMPANY_CHANCE, companyChance);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getCompanyChance() {
        return spf.getString(COMPANY_CHANCE, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setApplyEntity(String applyEntity) {
        Editor editor = spf.edit();
        AppData.saveData(APPLY_ENTITY, applyEntity);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getApplyEntity() {
        return spf.getString(APPLY_ENTITY, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setCollateralEntity(String collateralEntityEntity) {
        Editor editor = spf.edit();
        AppData.saveData(COLLATERAL_ENTITY, collateralEntityEntity);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public String getCollateralEntity() {
        return spf.getString(COLLATERAL_ENTITY, "");
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public void setApplyType(int applyType) {
        Editor editor = spf.edit();
        AppData.saveData(APPLY_TYPE, applyType);
        editor.commit();
    }

    /**
     * <p>
     * Title: setTermStart
     * </p>
     * <p>
     * Description:保存当前周数
     * </p>
     */
    public int getApplyType() {
        return spf.getInt(APPLY_TYPE, 0);
    }


    /**
     * <p>
     * Title: setCourseBg
     * </p>
     * <p>
     * Description:背景色调，0代表正常，1代表暖色，2代表冷色
     * </p>
     */
    public void setUserCompany(String user_company) {
        Editor editor = spf.edit();

        editor.putString(USER_COMPANY, user_company);
        editor.commit();
    }

    /**
     * <p>
     * Title: getCourseBg
     * </p>
     * <p>
     * Description:背景色调，0代表正常，1代表暖色，2代表冷色
     * </p>
     *
     * @return
     */
    public String getUserCompany() {

        return spf.getString(USER_COMPANY, "");
    }

    /**
     * @return the defalutPassword
     */
    public String getDefalutPassword() {
        return "00000000000000000";
    }

}
